package dtomap

import "regexp"

const (
	classRegexText = "class\\s*(\\S*)\\s*\\b"
	fieldRegexText = "public\\s*(\\S*)\\s*(\\S*)\\s*{?"
)

var (
	classRegex = regexp.MustCompile(classRegexText)
	fieldRegex = regexp.MustCompile(fieldRegexText)
)

type DtoParse struct {
}

func (dp *DtoParse) GetClassName(input string) string {
	if classRegex.MatchString(input) {
		return classRegex.FindStringSubmatch(input)[1]
	}
	return ""
}

func (dp *DtoParse) GetFiled(input string) (fieldType string, fieldName string) {
	if fieldRegex.MatchString(input) {
		subMatches := fieldRegex.FindStringSubmatch(input)
		fieldType = subMatches[1]
		fieldName = subMatches[2]
	}

	return
}
